import javax.swing.*;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;

public class DefaultValueTextField extends JTextField {

    private final String defaultValue;

    public DefaultValueTextField(String defaultValue) {
        super(defaultValue);
        this.defaultValue = defaultValue;
        addFocusListener(new FocusAdapter() {
            @Override
            public void focusLost(FocusEvent e) {
                if (getText().isEmpty()) {
                    setText(defaultValue);
                }
            }
        });
    }
}